﻿Public Class CandidateSet
    ' James D. Zoll
    '
    ' the CandidateSet class is used by the CandidateSetFinder
    ' class to hold information about gear sets being built by
    ' the iterative evaluation process.  This class is designed to
    ' be utilized primarily as a data type.

    Implements ICloneable

    ' Public members are accessible to the declaring scope.  Information includes
    ' the IDs of the items in each slot as well as the enchants and score information
    ' necessary to trim the candidates.
    Public itemIDs() As Integer
    Public fEnch As CalcManager.Enchants
    Public wEnch As CalcManager.Enchants
    Public hEnch As CalcManager.Enchants
    Public maxScore As Double
    Public minScore As Double

    Public Sub New(ByVal numPieces As Integer)
        ' Initialization requires redefining the item array to the correct size
        ' and setting both the minimum and maximum scores to zero.
        Try
            ReDim itemIDs(0 To numPieces - 1)
            maxScore = 0
            minScore = 0
        Catch ex As Threading.ThreadAbortException
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
        End Try
    End Sub

    Public Function clone() As Object Implements System.ICloneable.Clone
        ' Clone functionality is used to allow deep copying of the
        ' data types inside the class object to prevent the corruption
        ' of sets due to multiple variables pointing to the same object.
        Try
            Return New CandidateSet(UBound(itemIDs) + 1) With {.itemIDs = itemIDs.Clone, .fEnch = fEnch, .wEnch = wEnch, .hEnch = hEnch, .maxScore = maxScore, .minScore = minScore}
        Catch ex As Threading.ThreadAbortException
            Return New CandidateSet(UBound(itemIDs) + 1) With {.itemIDs = itemIDs.Clone, .fEnch = fEnch, .wEnch = wEnch, .hEnch = hEnch, .maxScore = maxScore, .minScore = minScore}
        Catch ex As Exception
            MessageBox.Show("An unexpected error has occurred. DK Optimize will exit.", "DK Optimize", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            ErrLogWriter.writeLog(ex)
            End
        End Try
    End Function

End Class
